/*
 * Model.cpp
 *
 *  Created on: 30/12/2011
 *      Author: faust
 */

#include "Model.h"
#include "SampleUtils.h"

Model::Model()
{

}

Model::~Model()
{
	if (model3D != 0) delete model3D;

}

Model* Model::create(JNIEnv* env, jobject modelObject, float markerWidth)
{
	Model* model = new Model();
	//LOG("Model::create - start loading model");

	model->translateX = 0.0f;
	model->translateY = 0.0f;
	// We must scale the model considering the size of the marker defined by the user
	model->scale = Model::TRACKABLE_WIDTH/markerWidth;


	jclass jModelClass = env->GetObjectClass(modelObject);

	jmethodID getModelDataMethodID = env->GetMethodID(jModelClass,
		"getModelData", "()Lcom/Utils3D/Model3D;");

	if (getModelDataMethodID == 0)
	{
		LOG("Model::create - Function getModelData not found.");
		return NULL;
	}

	jobject model3DObject = env->CallObjectMethod(modelObject, getModelDataMethodID);
	if (model3DObject == NULL)
	{
		LOG("Model::create - GetModelData() returned zero pointer");
		return NULL;
	}

	model->model3D = Model3D::create(env, model3DObject);

	//LOG("Model::create - model created successfully");

	return model;
}
